package com.auxgroup.smarthome;

import java.util.*;

/**
 * Created by kevinchen on 2017/9/5.
 * 家用空调控制协议表
 * 协议详见A1表
 */
public enum DatapointControlEnum {
    /**
     * A
     */
    TEMPERATURE("temperature",5,"A","设定温度",8,39),
    UP_DOWN_SWING("up_down_swing",3,"A","上下摆风",0,7),
    /**
     * B
     */
    LEFT_RIGHT_SWING("left_right_swing",3,"B","左右摆风",0,7),
    NOW_TIME_HOUR("now_time_hour",5,"B","当前小时",0,23),
    /**
     * C
     */
    HALF("half",1,"C","0.5度设置",0,1),
    AUTO_FOLLOWING_CODE("auto_following_code",1,"C","发随身感码",0,1),
    NOW_TIME_MINUTE("now_time_minute",6,"C","当前分钟",0,59),
    /**
     * D
     */
    WIND_SPEED_1("wind_speed_1",3,"D","风速选择",0,7),
    TIME_HOUR("timer_hour",5,"D","定时时间小时",0,23),
    /**
     * E
     */
    TURBO_SILENCE("turbo_silence",2,"E","强力、静音",0,2),
    TIME_MINUTE("timer_minute",6,"E","定时分钟",0,59),
    /**
     * F
     */
    AIR_CON_FUNC("air_con_func",3,"F","模式",0,7),
    FRESHING("freshing",1,"F","清新",0,1),
    FOLLOWING("following",1,"F","随身感",0,1),
    SLEEP_MODE("sleep_mode",1,"F","睡眠",0,1),
    FAHRENHEIT("fahrenheit",1,"F","温标",0,1),
    HUMAN_DETECTION("human_detection",1,"F","人感功能",0,1),
    /**
     * G
     */
    OBLIGATE_1("obligate_1",2,"G","预留1",0,3),
    ROOM_TEMERATURE("room_temperature",6,"G","室内温度（随身感）",-10,53),
    /**
     * H
     */
    OBLIGATE_2("obligate_2",2,"H","预留2",0,3),
    HUMIDITY("humidity",6,"H","室内湿度设定",29,90),
    /**
     * I
     */
    AC_TIMER("ac_timer",2,"I","定时",0,3),
    ON_OFF("on_off",1,"I","开关机",0,1),
    ELECTRIC_HEATING("electric_heating",1,"I","电热",0,1),
    ECO("eco",1,"I","ECO",0,1),
    CLEAN("clean",1,"I","清洁",0,1),
    HEALTHY("healthy",1,"I","健康",0,1),
    AIR_FRESHING("air_freshing",1,"I","空气清新",0,1),
    /**
     * J
     */
    OBLIGATE_3("obligate_3",1,"J","预留3",0,1),
    WIND_SPEED_2("wind_speed_2",7,"J","无极调速比例",0,100),
    /**
     * K
     */
    OBLIGATE_4("obligate_4",1,"K","预留4",0,1),
    AUTO_SCREEN("auto_screen",1,"K","显示自动",0,1),
    ELECTRIC_LOCK("electric_lock",1,"K","电子锁",0,1),
    SCREEN_ON_OFF("screen_on_off",1,"K","显示板打开",0,1),
    ANTI_FUNGUS("anti_fungus",1,"K","防霉",0,1),
    SLEEP_DIY("sleep_diy",1,"K","自定义睡眠",0,1),
    CONTROL_MODE("control_mode",2,"K","控制方式",0,3),

    /**
     * L
     * 备注：2017-09-08 power_limit_percent的取值范围修改为[0,100]
     */
    POWER_LIMIT("power_limit",1,"L","限电有效",0,1),
    POWER_LIMIT_PERCENT("power_limit_percent",7,"L","整机功率负荷百分比",0,100),

    /**
     * M
     */
    OBLIGATE_5("obligate_5",4,"M","预留5",0,15),
    TEMPERATURE_DECIMAL("temperature_decimal",4,"M","设定温度小数",0,9)
    ;

    /**
     * 数据点字段名称
     */
    private String name;

    /**
     * 在协议中二进制中所占bit位数
     */
    private int bitCount;
    /**
     * 中文描述
     */
    private String displayName;
    /**
     * 所在位置 A-M
     */
    private String position;
    /**
     * 最小值
     */
    private int min;
    /**
     * 最大值
     */
    private int max;

    DatapointControlEnum(String name, int bitCount, String position,String displayName,int min,int max) {
        this.name = name;
        this.bitCount = bitCount;
        this.position = position;
        this.displayName = displayName;
        this.min = min;
        this.max = max;
    }

    public String getPosition() {
        return position;
    }

    public String getName() {
        return name;
    }

    public int getBitCount() {
        return bitCount;
    }

    public int getMin() {
        return min;
    }

    public int getMax() {
        return max;
    }


    /**
     * key: 所在位置 A-M  value: A-M位置中所包含的对应数据点信息
     * @return 返回有序的映射map
     */
    public static Map<String,List<DatapointControlEnum>> getDatapointControlEnumMap(){
        Map<String,List<DatapointControlEnum>> datapointMap = new TreeMap<String,List<DatapointControlEnum>>();
        DatapointControlEnum[] values = DatapointControlEnum.values();
        for (int i = 0; i < values.length ; i++) {
            DatapointControlEnum value = values[i];
            List<DatapointControlEnum> datapointControlEnumList = datapointMap.get(value.getPosition());
            if (datapointControlEnumList == null){
                datapointControlEnumList = new ArrayList<DatapointControlEnum>();
                datapointMap.put(value.getPosition(),datapointControlEnumList);
            }
            datapointControlEnumList.add(value);
        }
        return datapointMap;
    }



}
